package com.xgk.boot.module.core.enums.biz;

import cn.hutool.core.util.ArrayUtil;
import com.xgk.boot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 订单状态枚举
 * 订单状态： 1-已提交 2-已预报  3-取消中  4-已取消  99-已作废
 * @author dhb52
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum implements ArrayValuable<Integer> {


    //已提交(保存时)
    SUBMITTED(1, "SUBMITTED"),
    //预报（下单成功后）
    FORECAST(2, "FORECAST"),

    //取消中
    CANCELLING(3, "CANCELLING"),
    //已取消
    CANCELED(4, "CANCELED"),

    //待配送
    PRE_TRANSIT(5, "PRE_TRANSIT"),

    //配送中
    IN_TRANSIT(6, "IN_TRANSIT"),

    //完成
    FINISHED(7, "FINISHED"),

    //异常
    ABNORMAL_FORECAST(11, "ABNORMAL_FORECAST"),

    //无效
    OBSOLETE(99, "OBSOLETE");

    public static final Integer[] ARRAYS = Arrays.stream(values()).map(OrderStatusEnum::getValue).toArray(Integer[]::new);

    /**
     * 类型
     */
    private final Integer value;
    /**
     * 名称
     */
    private final String name;

    @Override
    public Integer[] array() {
        return ARRAYS;
    }

    public static OrderStatusEnum valueOf(Integer interval) {
        return ArrayUtil.firstMatch(item -> item.getValue().equals(interval), OrderStatusEnum.values());
    }

}